import 'package:dio/dio.dart';
import 'package:fsharing/core/models/user_realname_query.dart';
import 'package:fsharing/core/services/auth.dart';
import 'package:fsharing/core/viewmodels/view_model.dart';

class UserRealnameQueryModel extends ViewModel {
  final Auth auth;
  String _errorMessage;
  UserRealnameQuery _data;

  UserRealnameQueryModel(this.auth) : super() {
    _initData();
  }

  String get errorMessage => _errorMessage;

  UserRealnameQuery get data => _data;

  Future<ViewState> _initData() async {
    viewState = ViewState.busy;
    try {
      _data = await auth.userRealnameQuery();
      viewState = ViewState.success;
    } catch (e) {
      _errorMessage = e is DioError ? e.message : e.toString();
      viewState = ViewState.error;
    }
    return viewState;
  }

  Future<ViewState> refreshData() async {
    try {
      _data = await auth.userRealnameQuery();
      viewState = ViewState.success;
    } catch (e) {}
    return viewState;
  }
}
